package helper

import "regexp"

// 正则校验

const (
	PhonePat    = "^([1][3,4,5,6,7,8,9])\\d{9}$"
	EmailPat    = "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$"
	PasswordPat = "^[a-zA-Z]\\w{5,17}$" // 密码(以字母开头，长度在6~18之间，只能包含字母、数字和下划线)
	QQPat = "[1-9][0-9]{4,}"	// 腾讯qq
)

var (
	EmailRegex    *regexp.Regexp
	PasswordRegex *regexp.Regexp
	PhoneRegex    *regexp.Regexp
	QQRegex    *regexp.Regexp
)

func init() {
	PhoneRegex = regexp.MustCompile(PhonePat)
	EmailRegex = regexp.MustCompile(EmailPat)
	PasswordRegex = regexp.MustCompile(PasswordPat)
	QQRegex = regexp.MustCompile(QQPat)
}

func CheckPhone(phoneNum string) bool {
	return PhoneRegex.MatchString(phoneNum)
}

func CheckEmail(email string) bool {
	return EmailRegex.MatchString(email)
}

func CheckPassword(password string) bool {
	return PasswordRegex.MatchString(password)
}

func CheckQQ(qq string) bool {
	return QQRegex.MatchString(qq)
}
